package wheel.conversion;

import java.util.Map;
import java.lang.reflect.Array;

public abstract class Converter {
    public abstract Class getTargetClass();
    
    public abstract Object convert(String value, Map<String, String> params);
    
    public Object convert(String value) {
        return convert(value, null);
    }
    
    public Object convert(String[] values, Map<String, String> params) {
        Object result = null;
        if (values != null) {
            int length = values.length;
            result = Array.newInstance(getTargetClass(), length);
            for (int i = 0; i < length; i++) {
                Array.set(result, i, convert(values[i], params));
            }
        }
        return result;
    }
    
    public Object convert(String[] values) {
        return convert(values, null);
    }
}
